package com.iams.manage.controller;

import com.github.pagehelper.Page;
import com.iams.activiti8.domain.dto.ActWorkflowFormDataDTO;
import com.iams.common.core.controller.BaseController;
import com.iams.common.core.domain.AjaxResult;
import com.iams.common.core.page.PageDomain;
import com.iams.common.core.page.TableDataInfo;
import com.iams.common.core.page.TableSupport;
import com.iams.manage.domain.BorrowTask;
import com.iams.manage.service.IBorrowTaskService;
import org.activiti.api.task.runtime.TaskRuntime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

@RestController
@RequestMapping("/task")
public class BorrowTaskController extends BaseController {

    @Autowired
    private TaskRuntime taskRuntime;


    @Autowired
    private IBorrowTaskService borrowTaskService;

    //获取我的代办任务
    @GetMapping(value = "/list")
    public TableDataInfo getTasks() {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Page<BorrowTask> hashMaps = borrowTaskService.selectProcessDefinitionList(pageDomain);
        return getDataTable(hashMaps);
    }


    //渲染表单
    @GetMapping(value = "/formDataShow/{taskID}")
    public AjaxResult formDataShow(@PathVariable("taskID") String taskID) {

        return AjaxResult.success(borrowTaskService.formDataShow(taskID));
    }

    //保存表单
    @PostMapping(value = "/formDataSave/{taskID}")
    public AjaxResult formDataSave(@PathVariable("taskID") String taskID,
                                   @RequestBody List<ActWorkflowFormDataDTO> formData ) throws ParseException {

        return toAjax(borrowTaskService.formDataSave(taskID, formData));
    }


    @GetMapping(value = "/historyFormDataShow/{taskID}")
    public AjaxResult historyFormDataShow(@PathVariable("taskID") String taskID) {

        return AjaxResult.success(borrowTaskService.historyFormDataShow(taskID));
    }



}
